<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/style.css">
    <title>盘点历史</title>
    <script src="js/jquery-1.10.1.min.js"></script>
    <script src="js/config.js"></script>
    <script src="js/message.js"></script>
</head>
<body>
<div class="nei_header">

    <h3>盘点历史</h3>
    <div class="rentu">
        <img src="images/renturn.png" alt="" onclick="window.history.back(-1)">
    </div>
    <div class="jix">
        <a href="pandian.html">盘点>></a>
    </div>
</div>


<div class="danju_con">
    <section style="position: absolute; top: 100px; width: 100%; height: 610px; overflow-y: auto;">
        <div class="main_box">
            <div class="cont_box editpro_box">
                <!--财务报表-->
                <table border="0" cellspacing="0" cellpadding="0" class="table" id="table_box">
                    <thead>
                    <tr>
                        <th>盘点日期</th>
                        <th>盘点单号</th>
                        <th>盘点前(个)</th>
                        <th>盘点后(个)</th>
                        <th>差异(个)</th>
                        <th>操作时间</th>
                        <th>创建人</th>
                    </tr>

                    </thead>
                    <tbody id="goodsBody">

                    </tbody>
                </table>
            </div>

        </div>
    </section>
</div>


<!--底部-->

<div class="mifooter">
    <input type="text" id="inventoryNo" placeholder="盘点单号">
    <input type="date" id="inventoryTime" placeholder="盘点时间">
    <button class="duo_btn" onclick="query()">查询</button>

    <div class="page">
        <span onclick="initTable(false)">上页</span>
        <span id="pageText">1/1</span>
        <span onclick="initTable(true)">下页</span>
    </div>


</div>

<!--底部-->


<!--洁清弹出框-->

<div id="bakdate" class="popup ">
    <div class="popupbox jieqing">
        <div class="pop_title">
            盘点明细 <span class="fet_out"> </span>
        </div>


        <section>
            <div class="main_box">
                <div class="cont_box editpro_box">
                    <!--财务报表-->
                    <table border="0" cellspacing="0" cellpadding="0" class="table">
                        <thead>
                        <tr>
                            <th>盘点日期</th>
                            <th>盘点单号</th>
                            <th>商品名称</th>
                            <th>商品编码</th>
                            <th>进货价</th>
                            <th>盘点前</th>
                            <th>盘点后</th>
                            <th>差异</th>
                        </tr>
                        </thead>
                        <tbody id="inventoryBody">
                        </tbody>
                    </table>
                </div>


            </div>
        </section>


        <div class="jie_btn">
            <button style="background-color: #0099cb;" onclick="$('.popup').fadeOut()">取消</button>
        </div>

    </div>
</div>

<script type="application/javascript">
    var page = 0;
    var total = 0;
    var inventoryTime = null;
    var inventoryNo = null;

    function someFunction(result) {
        let tableHtml = "";
        if (result.list == null || result.list.length <= 0) {
            $.message({
                message: "无数据",    //提示信息
                duration: 3000,
                type: 'success',           //显示类型，包括4种：success.error,info,warning 默认info
                showClose: false       //显示关闭按钮（默认：否）
            });
            return;
        } else {
            for (let m of result.list) {
                tableHtml +=
                    "<tr onclick=\"detail('" + JSON.stringify(m) + "')\">" +
                    "<td>" + m.inventoryTime + "</td>" +
                    "<td>" + m.inventoryNo + "</td>" +
                    "<td>" + m.beforeInventory + "</td>" +
                    "<td>" + m.afterInventory + "</td>" +
                    "<td>" + (m.difference == 0 ? "无" : m.difference) + "</td>" +
                    "<td>" + dateFtt("yyyy-MM-dd hh:mm:ss", new Date(m.createTime)) + "</td>" +
                    "<td>" + m.uname + "</td>" +
                    "</tr>";
            }
        }
        $("#goodsBody").html(tableHtml);
        total = result.pages;
        $("#pageText").text(page + "/" + total);
    }

    function query() {
        page = 0;
        total = 0;
        initTable(true);
    }

    function detail(m) {
        let d = JSON.parse(m);
        inventoryTime = d.inventoryTime;
        inventoryNo = d.inventoryNo;
        cashierPost("inventory/get.do", {inventoryNo: inventoryNo}, detailFunction);
    }

    function detailFunction(result) {
        let tableHtml = "";
        if (result == null || result.length <= 0) {
            $.message({
                message: "无数据",    //提示信息
                duration: 3000,
                type: 'success',           //显示类型，包括4种：success.error,info,warning 默认info
                showClose: false       //显示关闭按钮（默认：否）
            });
            return;
        } else {
            for (let m of result) {
                tableHtml +=
                    "<tr>" +
                    "<td>" + m.inventoryTime + "</td>" +
                    "<td>" + m.inventoryNo + "</td>" +
                    "<td>" + m.goodsName + "</td>" +
                    "<td>" + m.goodsCode + "</td>" +
                    "<td>" + m.purchasePrice + "</td>" +
                    "<td>" + m.beforeInventory + "</td>" +
                    "<td>" + m.afterInventory + "</td>" +
                    "<td>" + (m.difference == 0 ? "无" : m.difference) + "</td>" +
                    "</tr>";
            }
        }
        showpop('#bakdate');
    }

    $(function () {
        initTable(true)
    });

    function initTable(b) {
        if (b) {
            if (total == 0 && page > 0) {
                $.message({
                    message: "无数据",    //提示信息
                    duration: 3000,
                    type: 'info',           //显示类型，包括4种：success.error,info,warning 默认info
                    showClose: false       //显示关闭按钮（默认：否）
                });
                return;
            } else if (total != 0 && total == page) {
                $.message({
                    message: "已是末页",    //提示信息
                    duration: 3000,
                    type: 'warning',           //显示类型，包括4种：success.error,info,warning 默认info
                    showClose: false       //显示关闭按钮（默认：否）
                });
                return;
            }
            page++;
        } else {
            if (page == 1) {
                $.message({
                    message: "已是首页",    //提示信息
                    duration: 3000,
                    type: 'warning',           //显示类型，包括4种：success.error,info,warning 默认info
                    showClose: false       //显示关闭按钮（默认：否）
                });
                return;
            }
            page--;
        }
        let inventoryNo = $("#inventoryNo").val();
        cashierPost("inventory/list.do", {inventoryNo: inventoryNo, pageNo: page, pageSize: 10}, someFunction);
    }


    //弹框
    function showpop(id) {
        $(id).fadeIn();

        var h = ($(window).height() - $(id).children('.popup-box').height()) / 2;
        $(id).children('.popup-box').css('margin-top', h);
    }

    $('.fet_out').click(function () {
        $('.popup').fadeOut();
    });

</script>
<!--编辑弹窗-->

</body>
</html>